//
//  WEXStatusModel.swift
//  microBlog
//
//  Created by apple on 16/4/20.
//  Copyright © 2016年 Hill. All rights reserved.
//

import UIKit

class WEXStatusModel: NSObject {
    
    // 微博ID
    var id: Int64 = 0
    // 微博信息内容
    var text: String?
    // 微博的创建时间
    var created_at: String?
    // 来源
    var source: String?
    // 当前微博的用户信息
    var user: WEXUserModel?
    // 转发微博内容
    var retweeted_status: WEXStatusModel?
    // 配图
    var pic_urls: [WEXPicInfoModel]?

    
    
    init(dict:[String: AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
//            手动字典转模型
            guard let dict = value as? [String: AnyObject] else{
                
                return
            }
//            重载方法
            user = WEXUserModel(dict: dict)
            
        }else if key == "retweeted_status"{
            
            
            guard let dict = value as? [String: AnyObject] else{
                
                return
            }
            
            retweeted_status = WEXStatusModel(dict: dict)
            
        }else if key == "pic_urls" {
            
            guard let dicts = value as? [[String: AnyObject]] else{
                
                return
            }
//            定义一个可变数组，装载图片模型
            var tempArray = [WEXPicInfoModel]()
            for dict in dicts {
                
                let info = WEXPicInfoModel.init(dict: dict)
                
                tempArray.append(info)
                
            }
            
            pic_urls = tempArray
            
            
     
        
        }else{
            
//            键不为"user"的字典，照常使用kvc
            super.setValue(value, forKey: key)

            
        }
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }

}
